<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - 表单向导</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> <link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="../css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="../css/plugins/steps/jquery.steps.css" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="jumbotron">
                <form method="post" id="formid" action="./factory/createApp" enctype="multipart/form-data">
                    <h1>设计向导</h1>
                    <p>在桌面快速创建属于你自己的一个应用</p>
                    <p>应用名<input  name="appName" value="请输入搜索内容" type="text" class="form-control required"/>
                    </p>
                    <p><input type="file" name="app" class="btn btn-primary btn-lg" role="button">使用json文件快速添加配置
                    </p>
                    <p><input type="file" name="ico" class="btn btn-primary btn-lg" role="button">添加图标文件
                    </p>
                    <button type="button" onclick="mysubmmit()" id="creatapp" class="btn btn-primary btn-lg" role="button">提交</button>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 全局js -->
<script src="../js/jquery.min.js?v=2.1.4"></script>
<script src="../js/bootstrap.min.js?v=3.3.6"></script>

<!-- 自定义js -->
<script src="../js/content.js?v=1.0.0"></script>


<!-- Steps -->
<script src="../js/plugins/staps/jquery.steps.min.js"></script>

<!-- Jquery Validate -->
<script src="../js/plugins/validate/jquery.validate.min.js"></script>
<script src="../js/plugins/validate/messages_zh.min.js"></script>


<script>
    function mysubmmit(){
        $.ajax({
            type: "POST",
            url: "./factory/createApp",
            cache: false,
            data: new FormData($("#formid")[0]),
            processData: false,
            contentType: false,
            success: function (result) {
                console.log(result);
                // var jsonStr  = JSON.parse( result );
                // console.log(jsonStr);
                // if(jsonStr.state == "ok"){
                //     alert("添加应用成功，刷新页面可以看到");
                //     // window.parent.reload();
                //     // window.close();
                // }else{
                //     if(jsonStr.error=="error"){
                //         alert("文件初始化错误");
                //     }else{
                //         alert("请不要重复添加");
                //     }
                // }
            },
            error: function (err) {
            }
        });
    };
    $(document).ready(function () {


        $("#wizard").steps();

        $("#form2").steps({
            bodyTag: "fieldset",
            onStepChanging: function (event, currentIndex, newIndex) {
                // Always allow going backward even if the current step contains invalid fields!
                if (currentIndex > newIndex) {
                    return true;
                }

                // Forbid suppressing "Warning" step if the user is to young
                if (newIndex === 3 && Number($("#age").val()) < 18) {
                    return false;
                }

                var form = $(this);

                // Clean up if user went backward before
                if (currentIndex < newIndex) {
                    // To remove error styles
                    $(".body:eq(" + newIndex + ") label.error", form).remove();
                    $(".body:eq(" + newIndex + ") .error", form).removeClass("error");
                }

                // Disable validation on fields that are disabled or hidden.
                form.validate().settings.ignore = ":disabled,:hidden";

                // Start validation; Prevent going forward if false
                return form.valid();
            },
            onStepChanged: function (event, currentIndex, priorIndex) {
                // Suppress (skip) "Warning" step if the user is old enough.
                if (currentIndex === 2 && Number($("#age").val()) >= 18) {
                    $(this).steps("next");
                }

                // Suppress (skip) "Warning" step if the user is old enough and wants to the previous step.
                if (currentIndex === 2 && priorIndex === 3) {
                    $(this).steps("previous");
                }
            },
            onFinishing: function (event, currentIndex) {
                var form = $(this);

                // Disable validation on fields that are disabled.
                // At this point it's recommended to do an overall check (mean ignoring only disabled fields)
                form.validate().settings.ignore = ":disabled";

                // Start validation; Prevent form submission if false
                return form.valid();
            },
            onFinished: function (event, currentIndex) {
                var form = $(this);

                // Submit form input
                form.submit();
            }
        }).validate({
            errorPlacement: function (error, element) {
                element.before(error);
            },
            rules: {
                confirm: {
                    equalTo: "#password"
                }
            }
        });
    });
</script>




</body>

</html>
